home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
APP
/
A-D
/
BBEdit 2.2.2.sea
/
BBEdit 2.2.2
/
BBEdit Extensions
/
Sources
/
CapSentence.c
< prev
next >
Wrap
C/C++ Source or Header
|
1992-10-09
|
2KB
|
88 lines
#include "ExternalInterface.h"
static long get_handle_size(Handle h)
{
asm {
movea.l h, a0
_GetHandleSize
}
}
static void *strip_address(void *p)
{
asm {
move.l p, d0
_StripAddress
}
}
#define SENTENCE_END(c) ((c == '.') || (c == '!') || (c == '?'))
#define WHITE_SPACE(c) ((c == 0x09) || (c == 0x0D) || (c == ' '))
static Boolean CapitalizeSentences( unsigned char *p, long start, long end )
{
long i, j;
Boolean result = FALSE;
/* The first non-whitespace character should always be capitalized. */
j = start;
while (WHITE_SPACE(p[j]) && (j < end))
j++;
i = j;
p[j] &= 0xDF;
/* Now do the rest... */
while ( i < end )
{
while (! SENTENCE_END(p[i]) && (i < end))
i++;
if (i == end)
break;
if ((p[++i] == ' ') || (p[i] == 0x09) || (p[i] == 0x0D)) {
while ((i < end) && WHITE_SPACE(p[i]))
i++;
if (i == end)
break;
if ((p[i] >= 'a') && (p[i] <= 'z')) {
p[i] &= 0xDF;
result = TRUE;
};
};
}
return result;
}
pascal void main( ExternalCallbackBlock *callbacks, WindowPtr w )
{
Handle text;
Size size;
long selStart, selEnd, firstChar;
if (! w)
return;
if ( callbacks->version >= 2 ) {
text = callbacks->GetWindowContents( w );
size = get_handle_size(text);
callbacks->GetSelection(&selStart, &selEnd, &firstChar);
if (selStart == selEnd) {
selStart = 0;
selEnd = size;
}
if (CapitalizeSentences((unsigned char *)*text, (Size) selStart, (Size) selEnd))
callbacks->ContentsChanged( w );
};
}